//
//  KWLMyGrewupViewController.m
//  KWNLaywerClient
//
//  Created by 孔六五 on 15/2/2.
//  Copyright (c) 2015年 张明磊. All rights reserved.
//
#undef  GrewupUnSelectTextColor
#define GrewupUnSelectTextColor RGB(189,189,189)

#undef  GrewupSelectTextColor
#define GrewupSelectTextColor RGB(91, 165, 229)

#import "KWLMyGrewupViewController.h"
#import "RESideMenu.h"
#import "KFWLabelControlView.h"
#import "KFLMyGrewupRequest.h"
#import "KWLLoginViewController.h"
#import "Model_myGrewup.h"
#import "KFWTableViewCell.h"
#import "KFWBadgeButton.h"

@interface KWLMyGrewupViewController ()<UITableViewDataSource,UITableViewDelegate,KFWLabelControlViewDelegate,UIWebViewDelegate>

@property KFWGrewupLeftBtnType grewupLeftBtnType;
@property KFWGrewupModelType grewupModelType;

@property (nonatomic,strong) UITableView *tab_myLevel;
@property (nonatomic,strong) UITableView *tab_myMedal;
//@property (nonatomic,strong) UITableView *tab_exchange;
@property (nonatomic,strong) KFWLabelControlView *grewupLabelControl;
@property (nonatomic,strong) Model_myGrewup *myGrewup;
@property NSInteger myLevelSelect;
@property (nonatomic,strong) NSMutableArray *arr_myLevelSelect;
@property (nonatomic,strong) NSArray *arr_myMedalText;
@property (nonatomic,strong) UIWebView *web_exchange;

@end

@implementation KWLMyGrewupViewController

@synthesize grewupLeftBtnType;
@synthesize grewupModelType;
//@synthesize tab_exchange;
@synthesize tab_myLevel;
@synthesize tab_myMedal;
@synthesize grewupLabelControl;
@synthesize myGrewup;
@synthesize myLevelSelect;
@synthesize arr_myLevelSelect;
@synthesize arr_myMedalText;
@synthesize web_exchange;

- (id)initWithGrewupLeftBtnType:(KFWGrewupLeftBtnType)type;
{
    self = [super init];
    if (self) {
        self.grewupLeftBtnType = type;
    }
    return self;
}

- (id)initWithGrewupLeftBtnType:(KFWGrewupLeftBtnType)type andModel:(KFWGrewupModelType)modelType;
{
    self = [super init];
    if (self) {
        self.grewupLeftBtnType = type;
        self.grewupModelType = modelType;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    arr_myLevelSelect = [[NSMutableArray alloc] init];
    arr_myMedalText = [NSArray arrayWithObjects:@"再戳我一下就告诉你",@"别戳了，真的不知道",@"一大波勋章正在路上呢",@"多多答题可能有勋章哦", nil];
    myLevelSelect = -1;
    // Do any additional setup after loading the view.
    if (grewupLeftBtnType == KFWGrewupLeftBtnBackType) {
        [self ui_title:@"我的成长" withLeftImageName:@"button_back.png" withReftImageName:nil];
    }
    else if (grewupLeftBtnType == KFWGrewupLeftBtnMenuType)
    {
        [self ui_title:@"我的成长" withLeftImageName:@"btn_leftList.png" withReftImageName:nil];
    }
    [self.button_left addTarget:self action:@selector(grewupLeftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self creatLabelToControlShow];
//    [self creatGrewupTab];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc
{
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self getGrewupData];
}
- (void)grewupLeftBtnClick:(id)sender
{
    if (grewupLeftBtnType == KFWGrewupLeftBtnBackType) {
        [self popViewController];
    }
    else if (grewupLeftBtnType == KFWGrewupLeftBtnMenuType)
    {
        [[RESideMenu sharedInstance] presentMenuViewController];
        [MobClick event:@"caidan"];
    }
}

#pragma mark - 取数据 -
- (void)getGrewupData
{
    [SVProgressHUD showWithStatus:@"加载中..."];
    KFLMyGrewupRequest *request = [[KFLMyGrewupRequest alloc] initRequest];
    __weak KWLMyGrewupViewController *aself = self;
    [request startToRequestWithBlock:^(NSInteger stateCode, NSMutableArray *result) {
        switch (stateCode) {
            case 10000:
            {
                [SVProgressHUD dismiss];
                aself.myGrewup = [result objectAtIndex:0];
                if (!aself.tab_myLevel) {
                    [aself creatGrewupTab];
                }
                else
                {
                    [aself.tab_myLevel reloadData];
                    [aself.tab_myMedal reloadData];
                }
                
                switch (aself.grewupModelType) {
                    case KFWGrewupModelTypeMyLevel:
                    {
                        UILabel *label = (UILabel *)[aself.grewupLabelControl viewWithTag:TagOfView + KFWGrewupModelTypeMyLevel];
                        [aself.grewupLabelControl labelControlTap:[label.gestureRecognizers objectAtIndex:0]];
                    }
                        break;
                    case KFWGrewupModelTypeMyMedal:
                    {
                        UILabel *label = (UILabel *)[aself.grewupLabelControl viewWithTag:TagOfView + KFWGrewupModelTypeMyMedal];
                        [aself.grewupLabelControl labelControlTap:[label.gestureRecognizers objectAtIndex:0]];

                    }
                        break;
                    case KFWGrewupModelTypeExchange:
                    {
                        UILabel *label = (UILabel *)[aself.grewupLabelControl viewWithTag:TagOfView + KFWGrewupModelTypeExchange];
                        [aself.grewupLabelControl labelControlTap:[label.gestureRecognizers objectAtIndex:0]];
                    }
                        break;
                    default:
                        break;
                }
            }
                break;
            case 10003:
            {
                [SVProgressHUD dismiss];
                [aself grewupTokenIsFailure];
            }
                break;
            default:
            {
                NSString *msg = [result objectAtIndex:0];
                [SVProgressHUD dismissWithError:msg afterDelay:1.5];
            }
                break;
        }
    }];
}

#pragma mark - 替换下线 -
- (void)grewupTokenIsFailure{
    
    UIAlertView *alter_login;
    if(IOS8_VERSION){
        alter_login = [[UIAlertView alloc] initWithTitle:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    }
    else{
        alter_login = [[UIAlertView alloc] initWithTitle:nil message:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    }
    alter_login.tag = 10003;
    [alter_login show];
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (alertView.tag) {
        case 10003:{
            KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:6];
            [self pushViewController:login];
        }break;
            
        default:
            break;
    }
}

#pragma mark - 3个控制显示的label -
- (void)creatLabelToControlShow
{
    NSArray *arr = [NSArray arrayWithObjects:@"我的等级",@"我的勋章",@"积分兑换", nil];
    grewupLabelControl = [[KFWLabelControlView alloc] initWithLabNameArr:arr withFrame:CGRectMake(0, self.view_title_super.frame.origin.y + self.view_title_super.frame.size.height, MainScreenWidth, 44)];
    grewupLabelControl.delegate = self;
    [self.view addSubview:grewupLabelControl];
}

#pragma mark - 创建tab -
- (void)creatGrewupTab
{
    tab_myLevel = [[UITableView alloc] initWithFrame:CGRectMake(0, grewupLabelControl.frame.origin.y + grewupLabelControl.frame.size.height, MainScreenWidth, MainScreenHeight - grewupLabelControl.frame.origin.y - grewupLabelControl.frame.size.height) style:UITableViewStylePlain];
    tab_myLevel.backgroundColor = [UIColor clearColor];
    tab_myLevel.delegate = self;
    tab_myLevel.dataSource = self;
    tab_myLevel.hidden = NO;
    if(IOS7_VERSION)
    {
        tab_myLevel.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    }
    [self.view addSubview:tab_myLevel];
    
    tab_myMedal = [[UITableView alloc] initWithFrame:CGRectMake(0, grewupLabelControl.frame.origin.y + grewupLabelControl.frame.size.height, MainScreenWidth, MainScreenHeight - grewupLabelControl.frame.origin.y - grewupLabelControl.frame.size.height) style:UITableViewStylePlain];
    tab_myMedal.backgroundColor = [UIColor clearColor];
    tab_myMedal.separatorStyle = UITableViewCellSeparatorStyleNone;
    tab_myMedal.delegate = self;
    tab_myMedal.dataSource = self;
    tab_myMedal.hidden = YES;
    [self.view addSubview:tab_myMedal];
    
    web_exchange = [[UIWebView alloc] initWithFrame:CGRectMake(0, grewupLabelControl.frame.origin.y + grewupLabelControl.frame.size.height, MainScreenWidth, MainScreenHeight - grewupLabelControl.frame.origin.y - grewupLabelControl.frame.size.height)];
    [web_exchange setDelegate:self];
    web_exchange.scrollView.bounces = NO;
    [web_exchange loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.test.kuaifawu.com/LWNLayerClient/mygrowth"]]];
    web_exchange.hidden = YES;
    [self.view addSubview:web_exchange];

//    tab_exchange = [[UITableView alloc] initWithFrame:CGRectMake(0, grewupLabelControl.frame.origin.y + grewupLabelControl.frame.size.height, MainScreenWidth, MainScreenHeight - grewupLabelControl.frame.origin.y - grewupLabelControl.frame.size.height) style:UITableViewStylePlain];
//    tab_exchange.backgroundColor = [UIColor clearColor];
//    tab_exchange.delegate = self;
//    tab_exchange.separatorStyle = UITableViewCellSeparatorStyleNone;
//    tab_exchange.dataSource = self;
//    tab_exchange.hidden = YES;
//    [self.view addSubview:tab_exchange];
}

#pragma mark - UITableViewDelegate -
/**
 *  列表数据源
 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == tab_myLevel) {
        return 5;
    }
    else if(tableView == tab_myMedal) {
        return 2;
    }
    else{
        return 1;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == tab_myLevel)
    {
        if (indexPath.row == 0)
        {
            return 200;
        }
        else
        {
            //需要改
            if ([arr_myLevelSelect containsObject:[NSNumber numberWithInteger:indexPath.row]])
            {
                if (indexPath.row == 1) {
                    return 218;
                }
                else if (indexPath.row == 2) {
                    return 445;
                }
                else if (indexPath.row == 3) {
                    return 183;
                }
                else{
                    return 154;
                }
            }
            else
            {
                return 53;
            }
        }
    }
    else if(tableView == tab_myMedal)
    {
        if (indexPath.row == 0) {
            return 177;
        }
        else
        {
            return 282;
        }
    }
    else
    {
        return 0;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == tab_myLevel) {
        return [self tab_myLevelWithIndexPath:indexPath];
    }
    
    if (tableView == tab_myMedal) {
        return [self tab_myMedalWithIndexPath:indexPath];
    }
    
//    if (tableView == tab_exchange) {
//        return [self tab_exchangeWithIndexPath:indexPath];
//    }
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == tab_myLevel) {
        if (indexPath.row != 0)
        {
            if ([arr_myLevelSelect containsObject:[NSNumber numberWithInteger:indexPath.row]])
            {
                [arr_myLevelSelect removeObject:[NSNumber numberWithInteger:indexPath.row]];
            }
            else
            {
                [arr_myLevelSelect addObject:[NSNumber numberWithInteger:indexPath.row]];
            }
            
            [tab_myLevel reloadData];
        }
    }
    else if(tableView == tab_myMedal)
    {
        NSIndexPath *oneindex = [NSIndexPath indexPathForRow:0 inSection:0];

        NSIndexPath *otherindex = [NSIndexPath indexPathForRow:1 inSection:0];
        UITableViewCell *onecell = [tab_myMedal cellForRowAtIndexPath:oneindex];
        UITableViewCell *othercell = [tab_myMedal cellForRowAtIndexPath:otherindex];
        UIImageView *imageview_textqipao_other = (UIImageView *)[othercell viewWithTag:TagOfView + 3];
        UILabel *label_text_other = (UILabel *)[othercell viewWithTag:TagOfView + 4];
        UIImageView *imageview_textqipao_one = (UIImageView *)[onecell viewWithTag:TagOfView + 3];
        UILabel *label_text_one = (UILabel *)[onecell viewWithTag:TagOfView + 4];
        imageview_textqipao_other.hidden = YES;
        label_text_other.hidden = YES;
        imageview_textqipao_one.hidden = YES;
        label_text_one.hidden = YES;
    }
}

#pragma mark - myLevelcell自己的方法 -
- (UITableViewCell *)tab_myLevelWithIndexPath:(NSIndexPath *)indexPath
{
    static NSString *MyLevelOneCellIdentifier = @"MyLevelOneCellIdentifier";
    static NSString *MyLevelOtherCellIdentifier = @"MyLevelOtherCellIdentifier";
    UITableViewCell *oneCell = [tab_myLevel dequeueReusableCellWithIdentifier:MyLevelOneCellIdentifier];
    UITableViewCell *otherCell = [tab_myLevel dequeueReusableCellWithIdentifier:MyLevelOtherCellIdentifier];

    if (indexPath.row == 0) {
        if (oneCell == nil) {
            oneCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyLevelOneCellIdentifier];
            oneCell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            UILabel *label_left = [UIUtils creatLabel];
            label_left.tag = TagOfView + 1;
            label_left.textColor = RGB(151, 194, 180);
            label_left.frame = CGRectMake(40, 42, 80, 15);
            label_left.textAlignment = NSTextAlignmentCenter;
            label_left.font = [UIFont fontWithName:@"Futura-CondensedExtraBold" size:14];
            label_left.center = CGPointMake(57, 50);
            
            UILabel *label_center = [UIUtils creatLabel];
            label_center.textColor = RGB(54, 215, 165);
            label_center.tag = TagOfView + 2;
            label_center.frame = CGRectMake(135, 20, 80, 24);
            label_center.textAlignment = NSTextAlignmentCenter;
            label_center.font = [UIFont fontWithName:@"Futura-CondensedExtraBold" size:20];
            label_center.center = CGPointMake(MainScreenWidth/2, 32);

            UILabel *label_right = [UIUtils creatLabel];
            label_right.textColor = RGB(151, 194, 180);
            label_right.tag = TagOfView + 3;
            label_right.frame = CGRectMake(MainScreenWidth - 57 - 40, 42, 80, 15);
            label_right.textAlignment = NSTextAlignmentCenter;
            label_right.font = [UIFont fontWithName:@"Futura-CondensedExtraBold" size:14];
            label_right.center = CGPointMake(MainScreenWidth - 57, 50);

            UIImageView *imageview_line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 68, MainScreenWidth, 3)];
            imageview_line.image = [UIImage imageFileName:@"levelLine.png"];
            
            UIImageView *imageview_left = [[UIImageView alloc] initWithFrame:CGRectMake(0, 68, 16, 16)];
            imageview_left.image = [UIImage imageFileName:@"levelCircle.png"];
            imageview_left.center = CGPointMake(57, 69.5);
            imageview_left.tag = TagOfView + 4;
            
            UIImageView *imageview_center = [[UIImageView alloc] initWithFrame:CGRectMake(0, 68, 39, 39)];
            imageview_center.center = CGPointMake(MainScreenWidth/2, 69.5);
            imageview_center.image = [UIImage imageFileName:@"levelSelectCircle.png"];

            UIImageView *imageview_right = [[UIImageView alloc] initWithFrame:CGRectMake(0, 68, 16, 16)];
            imageview_right.center = CGPointMake(MainScreenWidth - 57, 69.5);
            imageview_right.image = [UIImage imageFileName:@"levelCircle.png"];
            imageview_right.tag = TagOfView + 5;

            UIImageView *imageview_qipao = [[UIImageView alloc] initWithFrame:CGRectMake((MainScreenWidth - 290)/2, 98, 290, 80)];
            imageview_qipao.image = [UIImage imageFileName:@"myGrewup_qipao.png"];
            
            UILabel *label_one = [UIUtils creatLabel];
            label_one.textColor = ColorOfQuestionList;
            label_one.font = FontOfHelveticaBold(13);
            label_one.frame = CGRectMake(30, imageview_qipao.frame.origin.y + 15 + 7, 290 - 30, 14);
            label_one.tag = TagOfView + 6;
            
            UILabel *label_two = [UIUtils creatLabel];
            label_two.textColor = ColorOfQuestionList;
            label_two.font = FontOfHelveticaBold(13);
            label_two.frame = CGRectMake(30, label_one.frame.origin.y + label_one.frame.size.height + 15, 57, 14);
            label_two.text = @"我的等级";
            
            UIImageView *imageview_progress_back = [[UIImageView alloc] initWithFrame:CGRectMake(label_two.frame.origin.x + label_two.frame.size.width + 5, label_two.frame.origin.y, 164, 14)];
            imageview_progress_back.image = [UIImage imageFileName:@"grewup_progress_back.png"];
            imageview_progress_back.tag = TagOfView + 7;

            UIImageView *imageview_progress = [[UIImageView alloc] initWithFrame:CGRectMake(imageview_progress_back.frame.origin.x + 1, imageview_progress_back.frame.origin.y+1, 162, 12)];
            imageview_progress.image = [[UIImage imageFileName:@"grewup_progress.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,10,0,10) resizingMode:UIImageResizingModeStretch];
            imageview_progress.tag = TagOfView + 8;
            
            UILabel *label_score = [UIUtils creatLabel];
            label_score.textColor = RGB(54, 215, 165);
            label_score.font = FontOfHelveticaBold(13);
            label_score.frame = CGRectMake(imageview_progress_back.frame.origin.x + imageview_progress_back.frame.size.width + 5, imageview_progress_back.frame.origin.y, 290 - 15 - 10 - label_two.frame.size.width - imageview_progress_back.frame.size.width, 14);
            label_score.tag = TagOfView + 9;

            [oneCell addSubview:label_left];
            [oneCell addSubview:label_center];
            [oneCell addSubview:label_right];
            [oneCell addSubview:imageview_line];
            [oneCell addSubview:imageview_left];
            [oneCell addSubview:imageview_center];
            [oneCell addSubview:imageview_right];
            [oneCell addSubview:imageview_qipao];
            [oneCell addSubview:label_one];
            [oneCell addSubview:label_two];
            [oneCell addSubview:imageview_progress_back];
            [oneCell addSubview:imageview_progress];
            [oneCell addSubview:label_score];
        }
        UILabel *label_left_ = (UILabel *)[oneCell viewWithTag:TagOfView + 1];
        UILabel *label_center_ = (UILabel *)[oneCell viewWithTag:TagOfView + 2];
        UILabel *label_right_ = (UILabel *)[oneCell viewWithTag:TagOfView + 3];
        UIImageView *imageview_left_ = (UIImageView *)[oneCell viewWithTag:TagOfView + 4];
        UIImageView *imageview_right_ = (UIImageView *)[oneCell viewWithTag:TagOfView + 5];
        UILabel *label_one_ = (UILabel *)[oneCell viewWithTag:TagOfView + 6];
        UIImageView *imageview_progress_back_ = (UIImageView *)[oneCell viewWithTag:TagOfView + 7];
        UIImageView *imageview_progress_ = (UIImageView *)[oneCell viewWithTag:TagOfView + 8];

        UILabel *label_score_ = (UILabel *)[oneCell viewWithTag:TagOfView + 9];

        if ([myGrewup.string_class integerValue] == 1) {
            label_left_.hidden = YES;
            imageview_left_.hidden = YES;
            label_right_.hidden = NO;
            imageview_right_.hidden = NO;
            label_center_.text = [NSString stringWithFormat:@"LV.%@",myGrewup.string_class];
            label_right_.text = [NSString stringWithFormat:@"LV.%ld",[myGrewup.string_class integerValue] + 1];
            
        }
        else if([myGrewup.string_class integerValue] == 20)
        {
            label_left_.hidden = NO;
            imageview_left_.hidden = NO;
            label_right_.hidden = YES;
            imageview_right_.hidden = YES;
            label_center_.text = [NSString stringWithFormat:@"LV.%@",myGrewup.string_class];
            label_left_.text = [NSString stringWithFormat:@"LV.%ld",[myGrewup.string_class integerValue] - 1];
        }
        else
        {
            label_left_.hidden = NO;
            imageview_left_.hidden = NO;
            label_right_.hidden = NO;
            imageview_right_.hidden = NO;
            label_center_.text = [NSString stringWithFormat:@"LV.%@",myGrewup.string_class];
            label_left_.text = [NSString stringWithFormat:@"LV.%ld",[myGrewup.string_class integerValue] - 1];
            label_right_.text = [NSString stringWithFormat:@"LV.%ld",[myGrewup.string_class integerValue] + 1];
        }
        
        NSInteger nextcount = [myGrewup.string_nextintegral integerValue] - [myGrewup.string_integral integerValue];
        if (nextcount<0) {
            nextcount = 0;
        }
        label_one_.text = [NSString stringWithFormat:@"当前等级%@级，距离下个等级还需要%li积分",myGrewup.string_class,(long)nextcount];
        CGFloat multiple = [myGrewup.string_integral integerValue] * 1.0 / [myGrewup.string_nextintegral integerValue];
        if (multiple >1) {
            multiple = 1.0;
        }
        CGFloat progressWidth = 162*multiple;
        UIEdgeInsets insets = imageview_progress_.image.capInsets;
        CGFloat minimumForegroundWidth = insets.left + insets.right;
        if (minimumForegroundWidth > progressWidth) {
            progressWidth = minimumForegroundWidth;
        }
        [imageview_progress_ setFrameWidth:progressWidth];
        label_score_.text = [NSString stringWithFormat:@"%@",myGrewup.string_integral];
        
        return oneCell;
    }
    else
    {
        if (otherCell == nil) {
            otherCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyLevelOtherCellIdentifier];
            otherCell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            UILabel *label_title = [UIUtils creatLabel];
            label_title.font = FontOfHelveticaBold(15);
            label_title.textColor = ColorOfQuestionList;
            label_title.frame = CGRectMake(24, 20, 230, 20);
            label_title.tag = TagOfView + 1;
            
            UIImageView *imageview_direction = [[UIImageView alloc] initWithFrame:CGRectMake(MainScreenWidth - 23 - 12, 23, 12, 8)];
            imageview_direction.tag = TagOfView + 2;

            UIImageView *imageview_content = [[UIImageView alloc] initWithFrame:CGRectZero];
            imageview_content.tag = TagOfView + 3;
            imageview_content.hidden = YES;
            
            [otherCell addSubview:label_title];
            [otherCell addSubview:imageview_direction];
            [otherCell addSubview:imageview_content];
        }
        UILabel *label_title_ = (UILabel *)[otherCell viewWithTag:TagOfView + 1];
        UIImageView *imageview_direction_ = (UIImageView *)[otherCell viewWithTag:TagOfView + 2];
        UIImageView *imageview_content_ = (UIImageView *)[otherCell viewWithTag:TagOfView + 3];
        
        switch (indexPath.row) {
            case 1:
            {
                label_title_.text = @"1、什么是积分？如何获取积分？";
                imageview_content_.image = [UIImage imageFileName:@"grewup_level_one.png"];
                imageview_content_.frame = CGRectMake((MainScreenWidth -290)/2, 46, 290, 152);
            }
                break;
            case 2:
            {
                label_title_.text = @"2、等级获得的标准是什么？";
                imageview_content_.image = [UIImage imageFileName:@"grewup_level_two.png"];
                imageview_content_.frame = CGRectMake((MainScreenWidth -290)/2, 46, 290, 374);
            }
                break;
            case 3:
            {
                label_title_.text = @"3、等级有什么用？";
                imageview_content_.image = [UIImage imageFileName:@"grewup_level_three.png"];
                imageview_content_.frame = CGRectMake((MainScreenWidth -290)/2, 46, 290, 116);
            }
                break;
            case 4:
            {
                label_title_.text = @"4、积分能花吗？";
                imageview_content_.image = [UIImage imageFileName:@"grewup_level_fore.png"];
                imageview_content_.frame = CGRectMake((MainScreenWidth -290)/2, 46, 290, 81);
            }
                break;

            default:
                break;
        }
        
        if ([arr_myLevelSelect containsObject:[NSNumber numberWithInteger:indexPath.row]]) {
            imageview_direction_.image = [UIImage imageFileName:@"grewup_arrow_top.png"];
            imageview_content_.hidden = NO;
        }
        else
        {
            imageview_direction_.image = [UIImage imageFileName:@"grewup_arrow_down.png"];
            imageview_content_.hidden = YES;
        }
        return otherCell;
    }
//    return nil;
}

#pragma mark - tab_myMedal自己的方法 -
- (UITableViewCell *)tab_myMedalWithIndexPath:(NSIndexPath *)indexPath
{
    static NSString *MyMedalOneCellIdentifier = @"MyMedalOneCellIdentifier";
    static NSString *MyMedalOtherCellIdentifier = @"MyMedalOtherCellIdentifier";
    UITableViewCell *oneCell = [tab_myMedal dequeueReusableCellWithIdentifier:MyMedalOneCellIdentifier];
    UITableViewCell *otherCell = [tab_myMedal dequeueReusableCellWithIdentifier:MyMedalOtherCellIdentifier];
    if (indexPath.row == 0)
    {
        if (oneCell == nil) {
            oneCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyMedalOneCellIdentifier];
            oneCell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            UILabel *label_top = [UIUtils creatLabel];
            label_top.backgroundColor = RGB(249, 249, 249);
            label_top.textColor = LabelUnSelectTextColor;
            label_top.frame = CGRectMake(0, 0, MainScreenWidth, 32);
            label_top.textAlignment = NSTextAlignmentCenter;
            label_top.text = @"时效型（点亮一个月）";
            label_top.font = FontOfHelveticaBold(13);
            CALayer *layer_top = [[CALayer alloc] init];
            layer_top.frame = CGRectMake(0, 31, MainScreenWidth, 1);
            layer_top.borderWidth = 1;
            layer_top.borderColor = RGB(232, 233, 232).CGColor;
            [label_top.layer addSublayer:layer_top];
            
            KFWBadgeButton *kfwBtn_answer = [KFWBadgeButton buttonWithType:UIButtonTypeCustom];
            kfwBtn_answer.frame = CGRectMake(51, 32+8, 92, 94);
            kfwBtn_answer.btn_indexPath = indexPath;
            kfwBtn_answer.tag = TagOfView + 1;
            kfwBtn_answer.badgeType = 0;
            [kfwBtn_answer addTarget:self action:@selector(btnOfTab_myMedalClick:) forControlEvents:UIControlEventTouchUpInside];
            
            KFWBadgeButton *kfwBtn_star = [KFWBadgeButton buttonWithType:UIButtonTypeCustom];
            kfwBtn_star.frame = CGRectMake(MainScreenWidth - 51 - 92, 32 + 8, 92, 94);
            kfwBtn_star.btn_indexPath = indexPath;
            kfwBtn_star.tag = TagOfView + 2;
            kfwBtn_star.badgeType = 0;
            [kfwBtn_star addTarget:self action:@selector(btnOfTab_myMedalClick:) forControlEvents:UIControlEventTouchUpInside];

            UIImageView *imageview_textqipao = [[UIImageView alloc] init];
            imageview_textqipao.frame = CGRectZero;
            imageview_textqipao.hidden = YES;
            imageview_textqipao.tag = TagOfView + 3;
            
            UILabel *label_text = [UIUtils creatLabel];
            label_text.font = FontOfSystem(12);
            label_text.textColor = [UIColor whiteColor];
            label_text.hidden = YES;
            label_text.textAlignment = NSTextAlignmentCenter;
            label_text.tag = TagOfView + 4;
            label_text.numberOfLines = 0;

            UILabel *label_bottom = [UIUtils creatLabel];
            label_bottom.backgroundColor = RGB(249, 249, 249);
            label_bottom.textColor = LabelUnSelectTextColor;
            label_bottom.frame = CGRectMake(0, 145, MainScreenWidth, 32);
            label_bottom.textAlignment = NSTextAlignmentCenter;
            label_bottom.text = @"永久型（可积累收藏）";
            label_bottom.font = FontOfHelveticaBold(13);
            CALayer *layer_bottom = [[CALayer alloc] init];
            layer_bottom.frame = CGRectMake(0, 31, MainScreenWidth, 1);
            layer_bottom.borderWidth = 1;
            layer_bottom.borderColor = RGB(232, 233, 232).CGColor;
            [label_bottom.layer addSublayer:layer_bottom];
            
            [oneCell addSubview:label_top];
            [oneCell addSubview:label_bottom];
            [oneCell addSubview:kfwBtn_answer];
            [oneCell addSubview:kfwBtn_star];
            [oneCell addSubview:imageview_textqipao];
            [oneCell addSubview:label_text];
        }
        
        KFWBadgeButton *kfwBtn_answer_ = (KFWBadgeButton *)[oneCell viewWithTag:TagOfView + 1];
        KFWBadgeButton *kfwBtn_star_ = (KFWBadgeButton *)[oneCell viewWithTag:TagOfView + 2];
        UIImageView *imageview_textqipao_ = (UIImageView *)[oneCell viewWithTag:TagOfView + 3];
        imageview_textqipao_.frame = CGRectMake(0, 0, 142, 38);

        if (myGrewup.string_label.intValue == 0) {
            [kfwBtn_answer_ setBackgroundImage:[UIImage imageFileName:@"grewup_badge.png"] forState:UIControlStateNormal];
            [kfwBtn_star_ setBackgroundImage:[UIImage imageFileName:@"grewup_badge.png"] forState:UIControlStateNormal];
            kfwBtn_answer_.badgeType = 0;
            kfwBtn_star_.badgeType = 0;
        }
        else if(myGrewup.string_label.intValue == 1)
        {
            [kfwBtn_answer_ setBackgroundImage:[UIImage imageFileName:@"grewup_badge_answer.png"] forState:UIControlStateNormal];
            [kfwBtn_star_ setBackgroundImage:[UIImage imageFileName:@"grewup_badge.png"] forState:UIControlStateNormal];
            kfwBtn_answer_.badgeType = 1;
            kfwBtn_star_.badgeType = 0;
        }
        else
        {
            [kfwBtn_answer_ setBackgroundImage:[UIImage imageFileName:@"grewup_badge.png"] forState:UIControlStateNormal];
            [kfwBtn_star_ setBackgroundImage:[UIImage imageFileName:@"grewup_badge_star.png"] forState:UIControlStateNormal];
            imageview_textqipao_.frame = CGRectMake(0, 0, 175, 38);
            kfwBtn_answer_.badgeType = 0;
            kfwBtn_star_.badgeType = 1;
        }
        
        return oneCell;
    }
    else
    {
        if (otherCell == nil) {
            otherCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyMedalOtherCellIdentifier];
            otherCell.selectionStyle = UITableViewCellSelectionStyleNone;
            CGFloat width_jiange = (MainScreenWidth - 92*3)/4;

            for (int i = 0; i<6; i++)
            {
                KFWBadgeButton *badgeBtn = [KFWBadgeButton buttonWithType:UIButtonTypeCustom];
                badgeBtn.btn_indexPath = indexPath;
                badgeBtn.tag = TagOfView + i + 10;
                badgeBtn.badgeType = 0;
                NSInteger line = i/3;
                NSInteger line_num = i%3;
                [badgeBtn setBackgroundImage:[UIImage imageFileName:@"grewup_badge.png"] forState:UIControlStateNormal];
                badgeBtn.frame = CGRectMake(width_jiange * (line_num + 1) + 92*line_num, 10*(line +1) + 94 * line, 92, 94);
                [badgeBtn addTarget:self action:@selector(btnOfTab_myMedalClick:) forControlEvents:UIControlEventTouchUpInside];
                [otherCell addSubview:badgeBtn];
            }
            
            UIImageView *imageview_textqipao = [[UIImageView alloc] init];
            imageview_textqipao.frame = CGRectZero;
            imageview_textqipao.hidden = YES;
            imageview_textqipao.tag = TagOfView + 3;
            
            UILabel *label_text = [UIUtils creatLabel];
            label_text.font = FontOfHelveticaBold(12);
            label_text.textColor = [UIColor whiteColor];
            label_text.hidden = YES;
            label_text.tag = TagOfView + 4;
            label_text.numberOfLines = 0;
            label_text.textAlignment = NSTextAlignmentCenter;
            
            [otherCell addSubview:imageview_textqipao];
            [otherCell addSubview:label_text];
        }
        UIImageView *imageview_textqipao_ = (UIImageView *)[otherCell viewWithTag:TagOfView + 3];
        imageview_textqipao_.frame = CGRectMake(0, 0, 142, 38);

        return otherCell;
    }
}

- (void)btnOfTab_myMedalClick:(id)sender
{
    KFWBadgeButton *btn = (KFWBadgeButton *)sender;
    UITableViewCell *cell = [tab_myMedal cellForRowAtIndexPath:btn.btn_indexPath];
    if (btn.btn_indexPath.row == 0) {
        NSIndexPath *otherindex = [NSIndexPath indexPathForRow:1 inSection:0];
        UITableViewCell *othercell = [tab_myMedal cellForRowAtIndexPath:otherindex];
        UIImageView *imageview_textqipao_other = (UIImageView *)[othercell viewWithTag:TagOfView + 3];
        UILabel *label_text_other = (UILabel *)[othercell viewWithTag:TagOfView + 4];
        imageview_textqipao_other.hidden = YES;
        label_text_other.hidden = YES;
    }
    else
    {
        NSIndexPath *otherindex = [NSIndexPath indexPathForRow:0 inSection:0];
        UITableViewCell *othercell = [tab_myMedal cellForRowAtIndexPath:otherindex];
        UIImageView *imageview_textqipao_other = (UIImageView *)[othercell viewWithTag:TagOfView + 3];
        UILabel *label_text_other = (UILabel *)[othercell viewWithTag:TagOfView + 4];
        imageview_textqipao_other.hidden = YES;
        label_text_other.hidden = YES;
    }
    UIImageView *imageview_textqipao_ = (UIImageView *)[cell viewWithTag:TagOfView + 3];
    UILabel *label_text_ = (UILabel *)[cell viewWithTag:TagOfView + 4];
    NSString *str = @"";
    imageview_textqipao_.hidden = NO;
    label_text_.hidden = NO;
//    imageview_textqipao_.image = [UIImage imageFileName:@"grewup_medal_qipao.png"];
    
    imageview_textqipao_.image = [[UIImage imageFileName:@"grewup_medal_qipao.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(20,80,10,100) resizingMode:UIImageResizingModeStretch];

    if (btn.btn_indexPath.row == 0) {
        if (btn.badgeType == 0) {
            int value = arc4random() % arr_myMedalText.count;
            str = [arr_myMedalText objectAtIndex:value];

        }
        else if(btn.badgeType == 1)
        {
            str = @"月答题数过百，好棒！";
        }
        else
        {
            str = @"答题过百评价最高，你就是明星！";
//            imageview_textqipao_.image = [UIImage imageFileName:@"grewup_medal_qipao_star.png"];
        }
    }
    else
    {
        int value = arc4random() % arr_myMedalText.count;
        str = [arr_myMedalText objectAtIndex:value];
        
        NSInteger i = btn.tag - 10 - TagOfView;
        NSInteger line_num = i%3;
        if (line_num == 0) {
            
        }
        else if(line_num == 1)
        {
            
        }
        else
        {
            
        }
    }
    CGSize labelsize = [UIUtils cgrectFor:str withFont:FontOfSystem(12) labWidth:100];
    imageview_textqipao_.frame = CGRectMake(0, 0, labelsize.width + 10, labelsize.height + 10);
    imageview_textqipao_.center = CGPointMake(btn.frame.origin.x + btn.frame.size.width/2, btn.frame.origin.y + btn.frame.size.height + 38/2);

    //    label_text_.frame = CGRectMake(imageview_textqipao_.frame.origin.x + (imageview_textqipao_.frame.size.width - labelsize.width)/2, imageview_textqipao_.frame.origin.y + 4 + 10, labelsize.width, labelsize.height);
    label_text_.frame = CGRectMake(imageview_textqipao_.frame.origin.x + (imageview_textqipao_.frame.size.width - labelsize.width)/2, imageview_textqipao_.frame.origin.y + 7, labelsize.width, labelsize.height);
    label_text_.text = str;
}

#pragma mark - tab_exchange自己的方法 -
- (UITableViewCell *)tab_exchangeWithIndexPath:(NSIndexPath *)indexPath
{
//    static NSString *ExchangeCellIdentifier = @"ExchangeCellIdentifier";
//    UITableViewCell *cell = [tab_exchange dequeueReusableCellWithIdentifier:ExchangeCellIdentifier];
//    if (cell == nil) {
//        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ExchangeCellIdentifier];
//        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        UIImageView *imageview_ = [[UIImageView alloc] initWithFrame:CGRectMake((MainScreenWidth - 303)/2, (tab_exchange.frame.size.height - 206)/2, 303, 206)];
//        imageview_.image = [UIImage imageFileName:@"grewup_exchange.png"];
//        
//        [cell addSubview:imageview_];
//    }
//    
//    return cell;
    return nil;
}
#pragma mark - KFWLabelControlViewDelegate -

- (void)clickLabelWithTag:(NSInteger)tag
{
    switch (tag) {
        case 0:
        {
            tab_myLevel.hidden = NO;
            tab_myMedal.hidden = YES;
            web_exchange.hidden = YES;
        }
            break;
        case 1:
        {
            tab_myLevel.hidden = YES;
            tab_myMedal.hidden = NO;
            web_exchange.hidden = YES;
        }
            break;
        case 2:
        {
            tab_myLevel.hidden = YES;
            tab_myMedal.hidden = YES;
            web_exchange.hidden = NO;
        }
            break;
        default:
            break;
    }
}
@end
